-- CS-013-09

DROP TABLE T029
GO

DROP TABLE T030
GO

DROP TABLE T025
GO

DROP TABLE T026
GO


---
--- CREATE TABLE: "dbo"."T025"
---
CREATE TABLE [dbo].[T025]
(
	[T025Id] int NOT NULL IDENTITY,
	[T011Entity] int NOT NULL,
	[T025NoFactura] varchar(32) NOT NULL,
	[T025Importe] decimal(18,6) NOT NULL,
	[T025FechaIngreso] datetime NOT NULL,
	PRIMARY KEY CLUSTERED ([T025Id])
)
GO
EXEC sp_addextendedproperty @name = 'MS_Description', @value = 'Tabla para registrar las facturas de CXC',
	@level0type = 'Schema', @level0name = 'dbo',
	@level1type = 'Table', @level1name = 'T025';
GO


---
--- CREATE INDEX: Relation_1
---
CREATE INDEX [Relation_1] ON [dbo].[T025]
(
	[T011Entity]
)
GO

---
--- CREATE INDEX: Index_1
---
CREATE UNIQUE INDEX [Index_1] ON [dbo].[T025]
(
	[T011Entity],
	[T025NoFactura]
)
GO

---
--- CREATE FOREIGN KEY CONSTRAINT: Relation_1
---
ALTER TABLE [dbo].[T025] ADD 
	FOREIGN KEY ([T011Entity])
		REFERENCES [dbo].[T011]([T011Entity])
		ON DELETE CASCADE
		ON UPDATE CASCADE
GO

---
--- CREATE TABLE: "T029"
---
CREATE TABLE [T029]
(
	[T029Id] int NOT NULL IDENTITY,
	[T025Id] int NOT NULL,
	[T029Fecha] datetime NOT NULL,
	[T029Anticipo] decimal NOT NULL,
	PRIMARY KEY CLUSTERED ([T029Id])
)
GO

---
--- CREATE INDEX: Relation_1
---
CREATE INDEX [Relation_1] ON [T029]
(
	[T025Id]
)
GO

---
--- CREATE FOREIGN KEY CONSTRAINT: Relation_1
---
ALTER TABLE [T029] ADD 
	FOREIGN KEY ([T025Id])
		REFERENCES [dbo].[T025]([T025Id])
		ON DELETE CASCADE
		ON UPDATE CASCADE
GO

---
--- CREATE TABLE: "dbo"."T026"
---
CREATE TABLE [dbo].[T026]
(
	[T026Id] int NOT NULL IDENTITY,
	[T011Entity] int NOT NULL,
	[T026NoFactura] varchar(32) NOT NULL,
	[T026Importe] decimal(18,6) NOT NULL,
	[T026FechaIngreso] datetime NOT NULL,
	PRIMARY KEY CLUSTERED ([T026Id])
)
GO
EXEC sp_addextendedproperty @name = 'MS_Description', @value = 'Tabla para registrar las facturas de CXP',
	@level0type = 'Schema', @level0name = 'dbo',
	@level1type = 'Table', @level1name = 'T026';
GO


---
--- CREATE INDEX: Relation_1
---
CREATE INDEX [Relation_1] ON [dbo].[T026]
(
	[T011Entity]
)
GO

---
--- CREATE INDEX: Index_1
---
CREATE UNIQUE INDEX [Index_1] ON [dbo].[T026]
(
	[T011Entity],
	[T026NoFactura]
)
GO

---
--- CREATE FOREIGN KEY CONSTRAINT: Relation_1
---
ALTER TABLE [dbo].[T026] ADD 
	FOREIGN KEY ([T011Entity])
		REFERENCES [dbo].[T011]([T011Entity])
		ON DELETE CASCADE
		ON UPDATE CASCADE
GO

---
--- CREATE TABLE: "T030"
---
CREATE TABLE [T030]
(
	[T030Id] int NOT NULL IDENTITY,
	[T026Id] int NOT NULL,
	[T030Fecha] datetime NOT NULL,
	[T030Anticipo] decimal NOT NULL,
	PRIMARY KEY CLUSTERED ([T030Id])
)
GO

---
--- CREATE INDEX: Relation_1
---
CREATE INDEX [Relation_1] ON [T030]
(
	[T026Id]
)
GO

---
--- CREATE FOREIGN KEY CONSTRAINT: Relation_1
---
ALTER TABLE [T030] ADD 
	FOREIGN KEY ([T026Id])
		REFERENCES [dbo].[T026]([T026Id])
		ON DELETE CASCADE
		ON UPDATE CASCADE
GO



DECLARE @T027IdScript as varchar(80)
DECLARE @T027Descripcion as varchar(360)
SET @T027IdScript='CS-013-09'
SET @T027Descripcion='Tablas para registrar los anticipos(pagos,cobros) de cxc y cxp'
INSERT INTO T027(T027IdScript,T027Descripcion,T027FechaRealizado) VALUES (@T027IdScript,@T027Descripcion,getdate())